package com.lianzhihui.romeex.ui.trade.adapter;

import android.content.Context;
import android.content.Intent;
import android.util.Log;
import android.view.View;
import android.widget.Button;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.lianzhihui.romeex.R;
import com.lianzhihui.romeex.bean.PledgeRecordsBean;
import com.lianzhihui.romeex.ui.trade.UpdateActivity;
import com.lianzhihui.romeex.utils.DateUtil;

import java.util.List;

/**
 * ProjectName: romeex
 * Package: com.lianzhihui.romeex.ui.trade.adapter
 * ClassName: ExtractFragmentAdapter
 * Description: 质押适配器
 * Author: zhanghong
 * CreateDate: 2020/10/30 17:38
 * UpdateUser: 更新者：
 * UpdateDate: 2020/10/30 17:38
 * UpdateRemark: 更新说明：
 * Version: 1.0
 */
public class PledgeRecordAdapter extends BaseQuickAdapter<PledgeRecordsBean.PledgeRecordBean, BaseViewHolder> {

    Context mContext;

    public PledgeRecordAdapter(@Nullable Context mContext, @Nullable List<PledgeRecordsBean.PledgeRecordBean> data) {
        super(R.layout.item_pledge_layout, data);
        this.mContext = mContext;
    }

    @Override
    protected void convert(@NonNull BaseViewHolder helper, PledgeRecordsBean.PledgeRecordBean item) {

        String status = item.getStatusStr();

        int base = (int) (Double.parseDouble(item.rusdBalance) / 100);
        Log.e("ramon", "质押数量：" + base);
        Log.e("ramon",item.canUpdate+"");
        if (item.canUpdate == 1) {
            //可升级
            helper.setGone(R.id.ll_ud, true);
        } else {
            helper.setGone(R.id.ll_ud, false);
        }

        Button bt_update = helper.getView(R.id.bt_update);
        bt_update.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mContext.startActivity(new Intent(mContext, UpdateActivity.class).putExtra("bean", item));
            }
        });

        helper.setText(R.id.tv_sum, item.getRusdBalance() + "");
        if (item.getStatus() == 4) {
            helper.setTextColor(R.id.tv_status, mContext.getResources().getColor(R.color.text666));
        } else {
            helper.setTextColor(R.id.tv_status, mContext.getResources().getColor(R.color.yellow));
        }
        helper.setText(R.id.tv_status, status);
        helper.setText(R.id.tv_pledge_sum, item.getTotalRetBalance() + " " + mContext.getString(R.string.text_rex));
        helper.setText(R.id.tv_destroy, item.getFee() + " " + mContext.getString(R.string.text_rex));

        helper.setText(R.id.tv_date, DateUtil.sec2Date(item.getAddTime()));

        helper.setVisible(R.id.ll_date_other, false);

        if (item.getStatusStr().equals("收益中")) {
            //有效剩余时间
            helper.setText(R.id.tv_date_name, "有效剩余时间");
            helper.setText(R.id.tv_date2, DateUtil.remaining(item.getExpireTime()));
            helper.setVisible(R.id.ll_date_other, true);
        }

        if (status.equals("已结束")) {
            //结束时间
            helper.setText(R.id.tv_date_name, "结束时间");
            if (item.getCanRelease() == 1) {
                helper.setText(R.id.tv_date2, DateUtil.sec2Date(item.getExtractTime()));
                helper.setVisible(R.id.ll_date_other, true);
            } else {
                helper.setText(R.id.tv_date2, DateUtil.sec2Date(item.getExpireTime()));
                helper.setVisible(R.id.ll_date_other, true);
            }

        }
    }
}
